var t = require;
var e = module;
var o = exports;
var n =
        (this && this.__extends) ||
        (function () {
            var t = function (e, o) {
                return (t =
                    Object.setPrototypeOf ||
                    ({__proto__: []} instanceof Array &&
                        function (t, e) {
                            t.__proto__ = e;
                        }) ||
                    function (t, e) {
                        for (var o in e) e.hasOwnProperty(o) && (t[o] = e[o]);
                    })(e, o);
            };
            return function (e, o) {
                function n() {
                    this.constructor = e;
                }
                t(e, o), (e.prototype = null === o ? Object.create(o) : ((n.prototype = o.prototype), new n()));
            };
        })(),
    r =
        (this && this.__spreadArrays) ||
        function () {
            for (var t = 0, e = 0, o = arguments.length; e < o; e++) t += arguments[e].length;
            var n = Array(t),
                r = 0;
            for (e = 0; e < o; e++) for (var a = arguments[e], i = 0, s = a.length; i < s; i++, r++) n[r] = a[i];
            return n;
        };
Object.defineProperty(o, "__esModule", {value: !0});
var a = t("AdCtrl"),
    i = t("Platforms"),
    s = t("TableRules"),
    c = (function (t) {
        function e(e, o, n) {
            for (var a = [], i = 3; i < arguments.length; i++) a[i - 3] = arguments[i];
            var s = t.call(this) || this;
            return (
                (s._onLoaded = function () {
                    s.loaded();
                }),
                (s._onResize = function (t) {
                    s.resize("onResize", t);
                }),
                (s._onError = function (t) {
                    s.log(JSON.stringify(t), !0), s.error();
                }),
                s.init.apply(s, r([e, o, n], a)) && (s.位置改变时重新创建 ? (s.xys = []) : s.create()),
                s
            );
        }
        return (
            n(e, t),
            (e.prototype.加载中 = function () {
                return "出错" != this.status && "加载中" == this.status;
            }),
            (e.prototype.可显示 = function () {
                return this.ad && "加载成功" == this.status;
            }),
            (e.prototype.clear = function () {
                this.ad &&
                    (this.ad.offLoad && this.ad.offLoad(this._onLoaded),
                    this.ad.offResize && this.ad.offResize(this._onResize),
                    this.ad.offError && this.ad.offError(this._onError),
                    this.ad.destroy && this.ad.destroy(),
                    (this.ad = null));
            }),
            (e.prototype.delayCreate = function () {
                var t = this;
                this.clear(),
                    i.default.delays.delay({
                        time: s.TableRules.delayCreateTime,
                        action: function () {
                            t.create();
                        }
                    });
            }),
            (e.prototype.create = function () {
                this.clear(),
                    this._createAd() &&
                        (this.位置改变时重新创建 ||
                            ((this.剩余展示次数 = this._同一内容展示次数 = this.同一内容展示次数()),
                            (this._同一内容展示时间 = this.同一内容展示时间()),
                            (this.开始加载时间 = new Date().getTime())),
                        this.监听onLoad && this.ad.onLoad(this._onLoaded),
                        this.监听onResize && this.ad.onResize(this._onResize),
                        this.ad.onError && this.ad.onError(this._onError),
                        (this.status = "加载中"));
            }),
            (e.prototype.show = function (t) {
                if (
                    ((this.rule = t),
                    this.位置改变时重新创建 &&
                        ((this.xys[0] == this.rule.dx &&
                            this.xys[1] == this.rule.dy &&
                            this.xys[2] == this.rule.offsetX &&
                            this.xys[3] == this.rule.offsetY) ||
                            ((this.xys[0] = this.rule.dx),
                            (this.xys[1] = this.rule.dy),
                            (this.xys[2] = this.rule.offsetX),
                            (this.xys[3] = this.rule.offsetY),
                            this.create())),
                    this.update(),
                    this.showing)
                );
                else if ((this.加载中() && this.检查超时(), this.加载中()));
                else {
                    if (!this.检查广告出错再次尝试时间()) return;
                    this.delayCreate();
                }
            }),
            (e.prototype.hide = function () {
                this.rule && ((this.rule = null), this.update());
            }),
            (e.prototype.update = function () {
                var t = this;
                if (this.rule) {
                    if (this.showing);
                    else if (this.可显示()) {
                        this.showing = !0;
                        var e = this.ad.show();
                        e &&
                            e.then &&
                            e
                                .then(
                                    function () {},
                                    function (e) {
                                        t._onError(e);
                                    }
                                )
                                .catch(function (e) {
                                    t._onError(e);
                                });
                    }
                } else
                    this.showing &&
                        ((this.showing = !1),
                        this.可显示() &&
                            (this.ad.hide(),
                            this.位置改变时重新创建 || (this.展示次数或展示时间达到预定值() && this.delayCreate())));
            }),
            (e.prototype.loaded = function () {
                (this.status = "加载成功"), this.update();
            }),
            (e.prototype.resize = function (t, e) {
                this.监听onLoad || this.loaded(),
                    console.log(this.name + " " + t + " " + JSON.stringify(e)),
                    this.update();
            }),
            (e.prototype.error = function () {
                (this.status = "出错"), this.log("error", !0);
            }),
            e
        );
    })(a.default);
o.default = c;
